<?php
/*
Template Name: 列表页-专题
 */
    get_header();
    $perPage = 24;  //每一页显示的数量
?>
<!-- 列表模块 -->
<div class="main-container">
    <div class="wrap">
        <p class="page-title">专题</p>
        <ul class="topic-list clearfix">
        <?php
            query_posts( array(
                'showposts'=>$perPage,
                'offset'=>$perPage * (max( 1, get_query_var('paged') )-1),
                'category__in' => 7
            ) );
            while(have_posts()) {
                the_post();
        ?>
            <li>
                <a href="<?php echo site_url() . get_post_meta($post->ID, "url")[0]; ?>" title="<?php the_title(); ?>">
                <?php the_post_thumbnail(array(261,185)); ?>
                </a>
            </li>
            <?php
                }
                wp_reset_query();
            ?>
        </ul>
        <div class="pagination" id="pagination">
        <?php 
            $allsearch = new WP_Query(array(
                'cat'=>7
            ));
            par_pagenavi($allsearch, $perPage); 
        ?>
        </div>
    </div>
</div>
<?php
    get_footer();
?>
<script>
(function() {
    var pageTotal = parseInt($('.pagination-total em').text());
    $('.pagination-go').on('click', function() {
        var val = parseInt($(this).siblings('input').val());
        if (isNaN(val) || val < 1 || val > pageTotal) {
            alert('请输入1~' + pageTotal + '之间的页码数');
            return;
        }
        var href = 'http://' + location.host + '/news/page/' + val;
        location.href = href;
    }); 
})();
</script>
</body>
</html>